<?php
class User 
{
	var $id;
	var $user_name;
    var $user_avatar;
    var $password;
    var $email;
    var $first_name;
    var $last_name;
    var $birthday;
    var $register_date;
    var $register_ip;
    var $visited_date;
    var $visited_ip;
    var $active_code;
    var $status;
    var $sign;
    var $group_id;
    var $login_count;
    
	function User($id, $user_name, $user_avatar, $password, $email, $first_name, $last_name,
	       $birthday, $register_date, $register_ip, 
	       $visited_date, $visited_ip, $active_code, $status, $sign, $group_id, $login_count) 
	{
		$this->$id = $id;
        $this->$user_name = $user_name;
        $this->$user_avatar = $user_avatar;
        $this->$password = $password;
        $this->$email = $email;
        $this->$first_name = $first_name;
        $this->$last_name = $last_name;
        $this->$birthday = $birthday;
        $this->$register_date = $register_date;
        $this->$register_ip = $register_ip;
        $this->$visited_date = $visited_date;
        $this->$visited_ip = $visited_ip;
        $this->$active_code = $active_code;
        $this->$status = $status;
        $this->$sign = $sign;
        $this->$group_id;
        $this->$login_count;
	}

	public function checkLogin($username, $password)
	{
		$query = "select * from users where user_name='$username' and password='$password'";
		$user = $DB->QueryRow($query);
				
		$id = $user["id"];
		$group_id = $user["group_id"];		
		//login sucessfull
		if($id && $group_id==1)
		{
		    #update info login user
		    $query = "  UPDATE users 
		                SET visited_date=NOW(),
		                visited_ip='". $_SERVER['REMOTE_ADDR'] ."',
		                login_count = login_count+1
		                WHERE id=$id";
		    
		    $DB->Update($query);
		    		    
		    #save session
		        
		    #$_SESSION["Login"]["id"]           = $id;
		    #$_SESSION["Login"]["group_id"] = $group_id;
		    #$_SESSION["Login"]["user_name"]    = $user["user_name"];
		    #$_SESSION["Login"]["FirstName"]    = $user[""];
		    
		    #$_SESSION["Login"] = new User($id, $user_name, $user_avatar, $password, $email, $first_name, $last_name,
		    #       $birthday, $register_date, $register_ip, 
		    #       $visited_date, $visited_ip, $active_code, $status, $sign, $group_id, $login_count);
		    
		    #echo "<script language='javascript'>alert('Login Sucessfull!');</script>";		    
		    return true;
		}
		else
		{
		    #echo "<script language='javascript'>alert('Login fail!');</script>";
		    return false;
		}	
	}
}
?>
